import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

public class thread {
    static ExecutorService executor;

    static {

        executor = new ThreadPoolExecutor(6,
                24,
                90,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(4096),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());


    }


    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        ExecutorService executor = thread.executor;
        //ExecutorService executor =  Executors.newCachedThreadPool();
        Map<Integer, Future<Integer>> map = new HashMap<>();
        try {
            for (int i = 0; i < 25; i++) {
                Future<Integer> future = executor.submit(new DivTask(100, 1));
                map.put(i, future);
            }

             Thread.sleep(3000);
            System.out.println("zhuxiancheng");
            for (Map.Entry<Integer, Future<Integer>> integerFutureEntry : map.entrySet()) {
                int ss = integerFutureEntry.getValue().get();
                System.out.println(integerFutureEntry.getKey() + "========" + ss);
            }
            long end = System.currentTimeMillis();
            System.out.println(end - start + "ms");

        } catch (Exception w) {
            w.printStackTrace();
        }

    }

    static class DivTask implements Callable<Integer> {
        int a, b;

        public DivTask(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public Integer call() throws Exception {
            //System.out.println(Thread.currentThread().getName()+"zixiancheng -- S");
            Integer result = 0;
            for (int i = 0; i < 30; i++) {
                result = a / b;
            }
            Thread.sleep(1000);
            //System.out.println(Thread.currentThread().getName()+"zixiancheng -- E"+result);
            return result;


        }
    }
}
